package com.mzj.saas.mservice.bill.repository;

import com.mzj.saas.mservice.bill.entity.RentBillRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface RentBillRelationRepository extends PagingAndSortingRepository<RentBillRelation, Long>, JpaSpecificationExecutor<RentBillRelation>, JpaRepository<RentBillRelation,Long> {

	RentBillRelation findByHouseIdAndRentBillId(String houseId,Long rentBillId);
	
	List<RentBillRelation> findByRentBillIdIn(List<Long> rentBillIds);
	
	@Query(value = "SELECT r.* FROM saas_rent_bill b LEFT JOIN saas_rent_bill_relation r ON b.id = r.rent_bill_id WHERE b.type = 1 AND b.payment_status = 0 AND r.contract_nubmer in (?1)", nativeQuery = true)
	List<RentBillRelation> findNoPayBill(List<String> contractNubmers);
}
